home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / TAWUG / TAWUG Disk No. 66 (SHK) / TAWUG66.shk / ASSEMBLY.LANG.1 (.txt) < prev    next >
AppleWorks Document  |  1988-03-11  |  11KB  |  177 lines

  1. O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
  2. NOTE:  This file was downloaded from a Denver bulletin board.
  3. Learning Apple 65C02 Assembly Language - Session one
  4. Some thoughts about this "class."E
  5. CI am hoping that folks will participate in this class by doing the 
  6. following:;
  7. 1) download the "class notes." (This file is session one)B
  8. @2) Send me email telling me that you downloaded (I am active as )
  9. "niemannross" on CACHE (303) 745-4960.)I
  10. G3) Read the file, try some things and participate in the discussion on G
  11. Ethe bbs. You will probably find it under board #4, basic programming 
  12. as a subtopic.
  13. GOnce again, this is an experiment. Let me know if you like it, and how 3
  14. it can be improved. And now...on with the show!!!
  15. WHY WOULD ANYONE WANT TO DO THINGS THE HARD WAY?
  16. FLet's face it. Assembly language is unfriendly, cryptic, difficult to I
  17. Guse and just one more !*^&$#! thing to learn. Why bother? Why not just H
  18. Fdwell in the land of Applesloth (applesoft - ha ha) forever and leave H
  19. Fthis machine language stuff to insomniacs with poor social skills? In F
  20. Dfact, my father has a Franklin Ace 1000 and would rather backup his A
  21. ?entire collection of software onto cassette tapes than program F
  22. Danything in assembly. It's ok. Dad's a nice guy and puts up with my H
  23. Fpeculiarities. But before you agree with him and trash this download, G
  24. Elet's examine two good reasons why assembly language really isn't so 
  25. evil.
  26. ! Speed !H
  27. FDad and I argue about this all the time. He says BASIC is faster, and I
  28. GI say assm (short for assembly language, ok?) is. Actually, I'll admit D
  29. Bhe is right in a way. It is faster to PROGRAM an application in a G
  30. Ehigher level language such as BASIC. That's why languages exist. But H
  31. Fif you've got to do something that requires runtime speed, folks, you H
  32. Fcan either fork over $200 for an accelerator board or you can program F
  33. Din assm. True, you can optimize BASIC, even compile it, but you are H
  34. Fonly trying to achieve the speed that assm takes for granted. Now, it I
  35. Gis possible to program a sloppy mess in assm that takes 5 working days I
  36. Gto run, but avoiding that is reasonably easy, and probably easier than E
  37. Ctrying to optimize an applesloth program. And try to write a music >
  38. <subroutine in applesloth without resorting to a ml (another .
  39. abbreviation...Machine Language) subroutine!
  40. ! Access !G
  41. EA main factor for programming a byte at a time is the access allowed B
  42. @to the machine itself. If you are going to try interfacing to a H
  43. Fnon-standard chunk of hardware, add something to the operating system H
  44. F(such as a new command for BASIC) or do anything that requires access E
  45. Cto machine addresses and such, your task is actually simplified by ?
  46. =using assm. Imagine trying to write a disk driver routine in E
  47. Capplesloth. Sure, not an everyday task. But using assm reduces the F
  48. Dtask to a manageable level SIMPLY BECAUSE WE DON'T HAVE TO OUTGUESS G
  49. ESOMEBODY ELSE'S PROGRAM, a program such as the BASIC interpreter. If H
  50. Fyou have to get a direct value from an address in basic, you PEEK and G
  51. Ehope that none of the code related to PEEK changes anything that you G
  52. Eneed to use. In assm, we perform one operation and know EXACTLY what /
  53. is going on and if anything has been changed.
  54. EOk, enough of that. If you're still reading, then you don't need any G
  55. Emore justifications for learning this thing. Great. Now, here's what 
  56. you should do next.
  57. ?1) Buy a good reference book on 65C02. There's bunches of them B
  58. @everywhere. When you look, make sure that the book you pick out A
  59. ?explains each of the commands in detail in a way that you feel H
  60. Fcomfortable with. Don't worry if you don't understand everything they I
  61. Gare talking about, that just means that you will be able to learn more I
  62. Gfrom it. Buy one on assembly language, and buy the technical reference H
  63. Fmanual for the particular computer you are using. Be aware that there ,
  64. ARE different manuals for the //e and //c.
  65. D   (Note: my apologies to you 65816 types out there. I am directing H
  66. Fthis class towards the 6502 and 65C02. Actually, this is still a good C
  67. Aplace to start for 65816, as the 6502 and 65C02 command sets are 
  68. subsets to 65816.)
  69. B2) Do yourself (and me) a favor and purchase an "assembler." This I
  70. Gsoftware will allow you to write and edit programs in a clear fashion, F
  71. Dtakes a lot of the grunt work out of programming assm and will make G
  72. Eyour family much happier. I will be using Merlin PRO, available from F
  73. Dyour local apple dealer or from Roger Wagner Publishing, Inc. 10761 I
  74. GWoodside Ave, Suite E, Santee, California 92071. Other suggestions are G
  75. Eapple's own edasm, Orca/M or Orca/EZ, and a gaggle of others. If you G
  76. Ehave questions, bounce them off of the bbs and we'll try to get some *
  77. feedback on what's the best one for you.
  78. EIf you have any notion about trying to poke code in by hand or about G
  79. Eusing the mini-assembler, please re-think. There are a LOT of things 5
  80. that neither of these methods will allow you to do.
  81. GI don't want to bring you into class on the first day, give you a list I
  82. Gof supplies and then send you home early. So, let's take a look at the ?
  83. star of our show and get a feel for what we are dealing with.
  84. FBelow is a simple Applesoft program. It asks for a number, and prints I
  85. that many dots, followed by a bell. Dumb, simple, but a quick example. 
  86.  10  GET A
  87.  20  PRINT ".";
  88.  30 A = A - 1
  89.  40  IF A > 0 THEN 20
  90.  50  PRINT  CHR$ (7)
  91.  60  END 
  92. FNow here is the same program written in assembly language. Whoa...you I
  93. Gsay! Its twice as long and looks like greek. Ok...don't panic. (By the ?
  94. =way, Hitchikers guide to the galaxy is recommended reading.) H
  95. FEverything means something, and is intended to make your life easier. E
  96. CFirst I'm going to label the parts, and then I'm going to describe 
  97. them.E
  98. -------------------------------------------------------------------/
  99.                Line                  Argument9
  100. Machine code    #    Labels   Opcode            RemarksE
  101. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -7
  102.                 1    ********************************0
  103.                 2    * Another useless program?
  104.                 3    * But a fun example of assembly language7
  105.                 4    ********************************
  106.                 57
  107.                 6    *-- Equates --------------------D
  108.                 7    COUT     EQU   $FDED      ;output a characterB
  109.                 8    BELL     EQU   $FBDD      ;beep the speaker@
  110.                 9    STROBE   EQU   $C010      ;keyboard flags:
  111.                 10   KEY      EQU   $C000      ;keyboard
  112.                 117
  113.                 12   *-- The program ----------------D
  114. 8000: 2C 10 C0  13            BIT   STROBE     ;clear the keyboard)
  115. 8003: AD 00 C0  14   GETKEY   LDA   KEYE
  116. 8006: 10 FB     15            BPL   GETKEY     ;wait for a keypress>
  117. 8008: 29 0F     16            AND   #$0F       ;ascii to hexC
  118. 800A: AA        17            TAX              ;save the keypress*
  119. 800B: A9 AE     18            LDA   #"."E
  120. C800D: 20 ED FD  19   PRINT    JSR   COUT       ;print a "." on the 
  121. screen#
  122. 8010: CA        20            DEX+
  123. 8011: D0 FA     21            BNE   PRINT@
  124. 8013: 20 DD FB  22            JSR   BELL       ;sound the bell:
  125. 8016: 60        23            RTS              ;and quit
  126. --End assembly, 23 bytes, Errors: 0
  127. Symbol table - alphabetical order:
  128. D   BELL    =$FBDD      COUT    =$FDED      GETKEY  =$8003      KEY  
  129. =$C000'
  130.    PRINT   =$800D      STROBE  =$C010
  131. Symbol table - numerical order:
  132. C   GETKEY  =$8003      PRINT   =$800D      KEY     =$C000   STROBE 
  133. =$C010'
  134.    BELL    =$FBDD      COUT    =$FDED
  135. ------------------------------------------------------------ -------H
  136. FNow remember, these are brief descriptions, designed to introduce and E
  137. Ctease you into the next class. We'll deal with each of these parts 1
  138. until you are good and tired of them. Carry on.
  139. "Machine Code"F
  140. DThis is the actual code that the 65C02 understands and can use. The I
  141. Gnumbers are all "hexadecimal," a big word we'll talk about a LOT more. C
  142. AThe first four numbers before the colon is the address that this I
  143. Ginformation will appear at. The pairs of numbers and letters after the A
  144. ?colon is the actual encoded data. This information is what the 
  145. assembler creates for us.
  146. "Line Number"C
  147. ASTRICTLY for the programmers convenience when editing. We do NOT @
  148. >require lines to have numbers (as in BASIC) and in fact, some I
  149. Gassemblers do not even produce these. Remember, these numbers are just 
  150. for you, the human.
  151. "Labels"I
  152. GThese are words, usually something like "COUT", or "START" or "GETLN". B
  153. @These are locations given to the assembler that it can use when D
  154. Bcomputing "addresses." These are an equivalent to line numbers in @
  155. >BASIC. They can also be used to represent values, much like a B
  156. @preassigned variable. (i.e. setting D$ equal to CHR$(4) for dos F
  157. Dcommands.) Incidentally, any line that starts with an "*" (at least F
  158. Dwhen using MERLIN) is recognized as a remark, just like applesloths 
  159. "Opcode"4
  160. This is a verb. The action. "Do this." More later.
  161. "Argument"G
  162. EThis is information that is used by the opcode. It can be a location 2
  163. or a chunk of data. Or a combination of the two.
  164. "Remarks"H
  165. FSomething that everyone could use more of. If you mail me source code H
  166. Fwithout remarks, I will write your name down in the national registry E
  167. Cof lousy programmers and send your name to a magazine subscription 
  168. service.
  169. DSo there...that ought to at least get you started. Now, here's your 
  170. assignment.
  171. >1) send me email telling me what a nice guy I am and that you 
  172. downloaded this stuff
  173. 2) post to the bulletin board any questions that you might have.
  174. 3) start thinking of a project you would like to work on.
  175. Asta la vista, saranoya, farewell and this is the end of this segment.
  176. ...niemannross
  177.